<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";

export default {
  data() {
    return {
      bscroll: null,
    };
  },
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    console.log(BScroll);
    this.bscroll = new BScroll(this.$refs.wrapper, {
      probeType: this.probeType,
      observeDOM: true,
      click: true,
      pullUpLoad: this.pullUpLoad,
      // mouseWheel:true,
    });
    // 监听滚动值
    this.bscroll.on("scroll", (options) => {
      // console.log(options)
      // 把滚动值发射给父组件
      this.$emit("scrollOptions", options);
    });

    //下拉加载更多
    this.bscroll.on("pullingUp", (res) => {
      this.$emit("pullingUp");
    });
    console.log(this.bscroll);
  },
  methods: {
    // 封装返回顶部按钮
    scrollToFn(x, y, time = 500) {
      // scrollTo是实例化bscroll里面的属性
      this.bscroll.scrollTo(x, y, time);
      // console.log(this.bscroll.scrollTo)
    },

    // 下拉加载更多
    finishPullUp() {
      // finishPullUp是实例化bscroll里面的属性
      this.bscroll.finishPullUp();
    },
  },
};
</script>

<style scoped>
</style>